package oa.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;

import oa.biz.MessageBiz;
import oa.entity.Message;
import oa.entity.MessageReception;
import oa.mapper.MessageMapper;
import oa.mapper.MessageReceptionMapper;

@Service
public class MessageBizImpl implements MessageBiz{
	@Autowired
	private MessageMapper messagemapper;
	@Autowired
	private MessageReceptionMapper messagercpmapper;
	@Override
	public List<Message> getAll(int receiverId) {
		return messagemapper.getAll(receiverId);
	}

	@Override
	public List<Message> getUnread(int receiverId,int isRead) {
		return messagemapper.getUnread(receiverId,isRead);
	}

	@Override
	public List<Message> getIndelete() {
		return messagemapper.getIndelete();
	}

	@Override
	public void messageadd(Message message) {
		messagemapper.messageadd(message);
		MessageReception messagercp=new MessageReception();
		messagercp.setId(0);	
		messagercp.setMessageId(messagemapper.selectaddId());
		messagercp.setReceiverId(message.getReceiversId());
		messagercp.setIsRead(0);
		messagercp.setStatus(message.getStatus());
		messagercpmapper.MessageReceptionadd(messagercp);

	}

	@Override
	public void messageupdate(Message message) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deletemessage(int id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int selectaddId() {
		return messagemapper.selectaddId();
	}

	@Override
	public List<Message> getAllSave(int receiverId) {
		// TODO Auto-generated method stub
		return messagemapper.getAllSave(receiverId);
	}

	@Override
	public Message fetchById(int id) {
		// TODO Auto-generated method stub
		return messagemapper.fetchById(id);
	}

	@Override
	public Message fetchByIdReaded(int id) {
		Message message =messagemapper.fetchByIdReaded(id);
/*		MessageReception messagercp =messagercpmapper.fetchByMessageId(id);
		int receiverId=messagercp.getReceiverId();
		int isRead =1;
		messagercpmapper.MessageReceptionupdate(isRead,id,receiverId);*/
		return message;
	}

}
